package com.tdam.CommunicationManager;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class WebMailHolder extends Holder
{
	
	private TextView txtMessage;
	private TextView txtwebMailDate;
	private TextView txtWebMail;
	private ImageView imgEdit;
	//private final long dayInMillis=86400000;
	
	@Override
	void fill(Object item) 
	{
		txtMessage.setText(((WebMailInfo)item).user);
		txtWebMail.setText(((WebMailInfo)item).message);
		
		Date today=new Date();
		today.setHours(0);
		today.setMinutes(0);
		today.setSeconds(0);
		Date messageDate=((WebMailInfo)item).timeStamp;
		long diff=messageDate.getTime()-today.getTime();
		SimpleDateFormat formatter=new SimpleDateFormat("dd/MM/yyyy");
		
		if(diff>=0)
		{
			formatter.applyPattern("HH:mm");
			txtwebMailDate.setText("Hoy " + formatter.format(messageDate));
		}
		else
			txtwebMailDate.setText(formatter.format(messageDate));
		
		switch(((WebMailInfo)item).edit)
		{
			case NOT_EDIT:
				imgEdit.setVisibility(View.GONE);
				break;
			case EDIT_MARKED:
				imgEdit.setImageResource(R.drawable.delete_down);
				imgEdit.setVisibility(View.VISIBLE);
				break;
			case EDIT_NOT_MARKED:
				imgEdit.setImageResource(R.drawable.delete_up);
				imgEdit.setVisibility(View.VISIBLE);
				break;
		}
		
	}

	@Override
	void link(View convertView)
	{
		txtMessage=(TextView) convertView.findViewById(R.id.txtContact);
		txtwebMailDate=(TextView) convertView.findViewById(R.id.txtwebMailDate);
		txtWebMail=(TextView) convertView.findViewById(R.id.txtWebMail);
		imgEdit=(ImageView) convertView.findViewById(R.id.imgEdit);
	}		
}		